package com.hejielife.singlethreadedexecution3;

/**
 * 2019年8月2日 上午10:29:27
 * 
 * @author hejielife
 * @despribe 模拟吃
 */
public class EaterThread2 extends Thread {
	private String name;
	private final Pair pair;

	public EaterThread2(String name, Pair pair) {
		this.name = name;
		this.pair = pair;
	}

	public void run() {
		while (true) {
			eat();
		}
	}

	public void eat() {
		synchronized (pair) {
			System.out.println(name + " takes up " + pair + ".");
			System.out.println(name + " is eating now, yam yam!");
			System.out.println(name + " puts down " + pair + ".");
		}
	}
}
